//
//  ViewController.m
//  ObjectArchiverDemo
//
//  Created by UniHan_iMac on 17/4/1.
//  Copyright © 2017年 UniHan_iMac. All rights reserved.
//

#import "ViewController.h"
#import "People.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 将自定义类的对象people进行编码，返回值为data，将data写入文件
    People *people = [[People alloc] init];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:people];
    
    // 存数据
    NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"people.plist"];
    [data writeToFile:filePath atomically:YES];
    
    // 取数据
    NSData *dataUnarchiver = [NSData dataWithContentsOfFile:filePath];
    
    // 对取出的数据进行反编码，得到自定义类的对象people
    [NSKeyedUnarchiver unarchiveObjectWithData:dataUnarchiver];
}





@end
